package com.iliad2x.FlexTransform.uiObject
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import mx.core.UIComponent;
	
	import com.iliad2x.FlexTransform.config.GlobalDatas;

	public class SelectionObject extends UIComponent
	{
		private var _sprite:Sprite;
		private var _shape:Shape;
		private var _targetObject:UIComponent;
		
		/** Setter for TargetObject **/
		public function set targetObject($value:UIComponent):void
		{
			_targetObject = $value;
			makeSelection();
		}
		
		/** Getter for TargetObject **/
		public function get targetObject():UIComponent
		{
			return _targetObject;
		}
		
		public function SelectionObject()
		{
		}
		
		/** Add Events for Selection-Object **/
		private function addEvents():void
		{
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
			addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
		}
		
		/** Mouse-Down Event Handler **/
		protected function onMouseDownHandler(e:MouseEvent):void
		{
			
		}
		
		/** Mouse-Up Event Handler **/
		protected function onMouseUpHandler(e:MouseEvent):void
		{
			
		}
		
		/** Make Selection-Object for Target-Object **/
		private function makeSelection():void
		{
			if(!_targetObject)
				return;
			
			if(!_sprite)
				addChild(_sprite = new Sprite);
			
			makeShape();
		}
		
		/** Make Shape-Object for Selection-Object **/
		private function makeShape():void
		{
			if(!_sprite)
				return;
			
			if(_shape)
				_sprite.removeChild(_shape);
			
			_shape = new Shape;
			_shape.graphics.lineStyle(GlobalDatas.lineTickness, GlobalDatas.lineColor, 0.5, false, "none");
			_shape.graphics.beginFill(0xFFFFFF, 0);
			_shape.graphics.drawRect(_targetObject.x, _targetObject.y, _targetObject.width-1, _targetObject.height-1);
			_shape.graphics.endFill();
			_sprite.addChild(_shape);
		}
		
		/** Make Anchor for TransformItem **/
		private function makeAnchor():void
		{
			
		}
	}
}